-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(users): add support for tenant level users #6708
base: main
Are you sure you want to change the base?
Conversation
crates/router/src/core/user_role.rs
Outdated
EntityType::Tenant => { | ||
return Err(UserErrors::InvalidRoleOperationWithMessage( | ||
"Tenant roles are not allowed for this operation".to_string(), | ||
) | ||
.into()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw error here? Is dashboard handling this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query above it will fetch 0 user_roles for entity type tenant where status is invitation_sent
, so we should throw error here instead of sending empty vector, if we have such user role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status should be 500
crates/router/src/services/authorization/roles/predefined_roles.rs
Outdated
Show resolved
Hide resolved
crates/api_models/src/user.rs
Outdated
pub organization_name: String, | ||
pub organization_details: Option<pii::SecretSerdeValue>, | ||
pub metadata: Option<pii::SecretSerdeValue>, | ||
pub merchant_name: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be a secret.
crates/router/src/core/user_role.rs
Outdated
EntityType::Tenant => { | ||
return Err(UserErrors::InvalidRoleOperationWithMessage( | ||
"Tenant roles are not allowed for this operation".to_string(), | ||
) | ||
.into()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status should be 500
crates/router/src/routes/app.rs
Outdated
@@ -1869,6 +1869,10 @@ impl User { | |||
.service( | |||
web::resource("/internal_signup").route(web::post().to(user::internal_user_signup)), | |||
) | |||
.service( | |||
web::resource("/create_tenant").route(web::post().to(user::create_tenant_user)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_merchant
-> creates merchant account
create_org
-> creates org account
create_tenant
-> creates user ??
@@ -124,18 +124,34 @@ impl JWTFlow { | |||
next_flow: &NextFlow, | |||
user_role: &UserRole, | |||
) -> UserResult<Secret<String>> { | |||
let (merchant_id, profile_id) = | |||
utils::user_role::get_single_merchant_id_and_profile_id(state, user_role).await?; | |||
let (org_id, merchant_id, profile_id) = match user_role.entity_type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simplified.
crates/router/src/core/user.rs
Outdated
let key_store = state | ||
.store | ||
.get_merchant_key_store_by_merchant_id( | ||
key_manager_state, | ||
&merchant_id, | ||
&state.store.get_master_key().to_vec().into(), | ||
) | ||
.await | ||
.change_context(UserErrors::InternalServerError) | ||
.attach_printable("Error while fetching the key store by merchant_id")?; | ||
|
||
let merchant_account = state | ||
.store | ||
.find_merchant_account_by_merchant_id(key_manager_state, &merchant_id, &key_store) | ||
.await | ||
.change_context(UserErrors::InternalServerError) | ||
.attach_printable("Error while fetching the merchant_account by merchant_id")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be skipped is below function only requires merchant id and org id and not the whole merchant account.
Type of Change
Description
Additional Changes
Motivation and Context
Closes #6707
How did you test it?
Api for create tenant:
Response: 200 Ok, if tenant_admin got created successfully
A tenant can login with email and password and continue with 2FA, he will land into any one of organization existing for tenant.
Create Org Api, (works for tenant users only)
Response will be 200 OK if the org got created success fully (1 org with 1 merchant and 1 profile)
After getting the login token tenant admin can switch to any org in the tenancy.
Checklist
cargo +nightly fmt --all
cargo clippy